package KeTangLian;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class DBManager2 {
public static int excuteUpdate(String sql) {
	
	try {
		//1 加载驱动
		Class.forName("com.mysql.jdbc.Driver");
		System.out.println("执行成功");
		//2 连接数据库
		Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/java十一章", "root", "123456");
		System.out.println("sql执行成功");
		//3 创建执行sql语句
		Statement statement=connection.createStatement();
		//4 对结果进行处理
		int result=statement.executeUpdate(sql);
		System.out.println(result>0?"成功":"失败");
		//5 关闭
		statement.close();
		connection.close();
		return result;
	} catch (ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.out.println("执行失败");
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.out.println("sql执行失败");
    }
	return 1;
}
public static int excuteQuery() {
	
	return 1;
}
}
